#include <stdio.h>
#include <string.h>
#include <openssl/md5.h>
#include <openssl/sha.h>


int main(int argc, char *argv[])
{
	int i;
	unsigned char md[64];
	unsigned char sha[64];
	unsigned char buf[64];
	MD5_CTX ctx;
	SHA_CTX sha_ctx;

#define SHA_LEN	20
#define MD5_LEN	16

	if (argc <= 1) {
		return -1;
	}

	MD5_Init(&ctx);
	MD5_Update(&ctx, argv[1], SHA_LEN * 2);
	MD5_Final(md, &ctx);

	for (i = 0; i < MD5_LEN / 2; i++) {
		snprintf(buf + 2 * i, 3, "%02x", md[i + MD5_LEN / 2] ^ 0xff);
	}

	SHA1_Init(&sha_ctx);
	SHA1_Update(&sha_ctx, md, MD5_LEN);
	SHA1_Final(sha, &sha_ctx);

	for (i = MD5_LEN / 2; i < MD5_LEN; i++) {
		snprintf(buf + 2 * i, 3, "%02x", sha[i] ^ md[i]);
	}
	printf("%s\n", buf);

	return 0;
}

